package com.aolong.archives.core.sysmanage.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.aolong.archives.core.sysmanage.dao.IMenuDao;
import com.aolong.archives.core.sysmanage.entity.MenuTreeEntity;
import com.rock.platform.dao.BaseDao;

public class MenuDao extends BaseDao implements IMenuDao{

	public List<MenuTreeEntity> findMenuByParentId(String strParentId)
	{
		String strSql = "";
			
		if (strParentId.equals("-1"))
		{
			strSql =  "select menuId id,parentId,'' text,menuName,menuNameEn, menuCode, pageUrl," +
					" (case when(select COUNT(0) from TSM_Menu where parentId = t.menuId) > 0 then 0 else 1 end) leaf " +
					" from TSM_Menu t where parentId is null order by displayOrder";
			return super.findByNativeSql(strSql, MenuTreeEntity.class);
		}
		else
		{
			strSql = "select menuId id,parentId,'' text,menuName,menuNameEn,menuCode,pageUrl," +
					 " (case when(select COUNT(0) from TSM_Menu where parentId = t.menuId) > 0 then 0 else 1 end) leaf " +
					 "  from TSM_Menu t where parentId =:parentId order by displayOrder";
			Map<String,Object> paras = new HashMap<String,Object>();
			paras.put("parentId", strParentId);
			return super.findByNativeSql(strSql, MenuTreeEntity.class, paras);
		}
	}
}
